package com.test3;

import java.util.HashMap;

/**
 * HashMap使用
 * 存储结构：哈希表（数组+链表+红黑树）
 */
public class HashMapTest {
    public static void main(String[] args) {
        HashMap<Students,String> stu = new HashMap<>();
        //添加元素
        Students s1 = new Students("叶凡",100);
        Students s2 = new Students("姬皓月",90);
        Students s3 = new Students("黑皇",80);
        stu.put(s1,"地球");
        stu.put(s2,"北斗");
        stu.put(s3,"紫薇");
        System.out.println(stu);//{Students{name='姬皓月', age=90}=北斗, Students{name='黑皇', age=80}=紫薇, Students{name='叶凡', age=100}=地球}
        stu.put(new Students("黑皇",80),"北斗");
        System.out.println(stu);//重写了equals和hashcode方法，所以添加失败

        //删除、遍历、判断和上面一样
    }

}
